from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


class User(db.Model):
    __tablename__ = "user"
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(30), unique=True)
    password = db.Column(db.String(64))
    role = db.Column(db.String(30))
    avatar = db.Column(db.String(100))
    email = db.Column(db.String(30))

    def __repr__(self):
        return "User:%s" % self.name


class Passenger(db.Model):
    __tablename__ = "passsenger"
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}
    name = db.Column(db.String(18))
    kind = db.Column(db.String(56))
    card = db.Column(db.String(24), primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)

    def __repr__(self):
        return "Passenger:%s" % self.name


class Train(db.Model):
    __tablename__ = "train"
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}
    train_no = db.Column(db.String(20), primary_key=True)
    train_number = db.Column(db.String(20), primary_key=True)
    train_carriage = db.Column(db.Integer)
    start_station = db.Column(db.String(20))
    end_station = db.Column(db.String(20))
    start_time = db.Column(db.String(20))
    end_time = db.Column(db.String(20))
    arrive_day = db.Column(db.String(20), primary_key=True)

    def __repr__(self):
        return "Train:%s" % self.train_no


class Parking(db.Model):
    __tablename__ = "parking"
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}
    train_no = db.Column(db.String(20), db.ForeignKey("train.train_no"), primary_key=True)
    train_number = db.Column(db.String(20))
    station_no = db.Column(db.String(20), primary_key=True)
    station_name = db.Column(db.String(20))
    arrive_day = db.Column(db.String(20), primary_key=True)
    arrive_time = db.Column(db.String(20))
    start_time = db.Column(db.String(20))




class Seat(db.Model):
    __tablename__ = "seat"
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}
    train_no = db.Column(db.String(20), db.ForeignKey("train.train_no"), primary_key=True)
    carriage_no = db.Column(db.String(20), primary_key=True)
    arrive_day = db.Column(db.String(20), primary_key=True)
    seat_type = db.Column(db.String(16))
    seat_count = db.Column(db.Integer)

    def __repr__(self):
        return "Seat:%s" % self.train_no


class Orders(db.Model):
    __tablename__ = "orders"
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}
    id = db.Column(db.String(40), primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    passenger_card = db.Column(db.String(24))
    train_no = db.Column(db.String(20), db.ForeignKey("train.train_no"))
    arrive_day = db.Column(db.String(20))
    start_station_no = db.Column(db.String(20))
    start_station_name = db.Column(db.String(20))
    end_station_no = db.Column(db.String(20))
    end_station_name = db.Column(db.String(20))
    carriage_no = db.Column(db.String(20))
    seat_no = db.Column(db.String(20))
    price = db.Column(db.String(20))
    create_time = db.Column(db.DateTime)
    status = db.Column(db.String(20))

    def __repr__(self):
        return "Order:%s" % self.id
